﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Bzure.Mvc.Html
{
    public static class ResourceHelper
    {
        public static string ImageResource(this HtmlHelper helper, string Location, string ImageName)
        {
            string url = Actor.Public.Url().RouteUrl("ResourceAccess_Image", new { location = Location, id = ImageName });
            return url;
        }
        public static string StyleResource(this HtmlHelper helper, string Location, string StyleName)
        {
            string url = Actor.Public.Url().RouteUrl("ResourceAccess_CSS", new { location = Location, id = StyleName });
            return helper.Style(url);
        }
        static string Style(this HtmlHelper helper, string url)
        {
            // Create tag builder
            var builder = new TagBuilder("link");
            // Add attributes
            builder.MergeAttribute("href", url);
            builder.MergeAttribute("rel", "stylesheet");
            builder.MergeAttribute("type", "text/css");
            // Render tag
            return builder.ToString(TagRenderMode.SelfClosing);
        }
        public static MvcHtmlString ScriptResource(this HtmlHelper helper, string Location, string ScriptName)
        {
            string url = Actor.Public.Url().RouteUrl("ResourceAccess_Script", new { location = Location, id = ScriptName });
            return helper.Script(Actor.Public.Url().ThemeContent(url));
        }
        static MvcHtmlString Script(this HtmlHelper helper, string url)
        {
            string s = string.Format("<script src=\"{0}\" type=\"text/javascript\"></script>", url);

            return MvcHtmlString.Create(s);
        }
    }
}
